function [eta0_cal,phi_cal,c_cal] = cal_fun_find_pscc(disc_target,markup_target,al_target,d,del,g)
%calibration file finding parameters eta0,phi,c given targets for discount, markup, probability of sale

options = optimoptions('fsolve','TolFun',1e-9,'TolX',1e-9,'StepTolerance',1e-9,'Display','final');
u=1;be=.95^(1/12);kap0=1;mu0=1;ent=1-(1+g)*(1-d);

%find phi targeting markup target, with eta0 set to target discount target given phi
markup_fun=@(phi) cal_fun_markup_pscc(cal_fun_find_helper_pscc(phi,disc_target,al_target,d,del,g),phi,al_target,d,del,g)-markup_target;
[phi_cal,res,flag]=fsolve(markup_fun,2,options);%find selling cost parameter
eta0_cal=cal_fun_find_helper_pscc(phi_cal,disc_target,al_target,d,del,g);%recover corresponding matching function parameter

%recover steady state
%def of growth: 1+g=(1-del)*(1+al*eta*shat)
eta_shat=((1+g)/(1-del)-1)/al_target;%given probability of sale, find steady state eta*shat
%eqm condition: 1+eta*shat=phi/(phi-1)*el/(1-el) where elasticity satisfies el/(1-el)=1/th^eta0 (see proof of Proposition 2)
th_fun=@(eta0_temp) ((phi_cal/(phi_cal-1))/(1+eta_shat))^(1/eta0_temp);%eqm condition yields implied theta given matching function parameter
th=th_fun(eta0_cal);%evaluate th
shat=eta_shat/eta_pscc(th_fun(eta0_cal),mu0,eta0_cal);%evaluate shat

%eqm condition (see equation A.3 in online appendix) pins down corresponding cost
res_fun=@(c) (u-c-be*(1-ent-(1-d)*(1-del))*kap_pscc(shat,kap0,phi_cal)/eta_shat-(1-be+be*ent)*shat*kap_s_pscc(shat,kap0,phi_cal)/eta_shat)/(-kap_n_pscc(shat,kap0,phi_cal)*(1-be*(1-d)*(1-del)*(1-mu_pscc(th,mu0,eta0_cal))))-1;
c_cal=fsolve(res_fun,.5,options);
end
